package com.wanmait.wisdom.manage.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wanmait.wisdom.entity.Staff;
import com.wanmait.wisdom.manage.service.ManageStaffService;
import com.wanmait.wisdom.mapper.OfficeMapper;
import com.wanmait.wisdom.mapper.StaffMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
@Transactional(rollbackFor = Exception.class)
public class ManageStaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements ManageStaffService {
    @Resource
    private StaffMapper staffMapper;

    @Resource
    private OfficeMapper officeMapper;

//    @Override
//    public Page<Staff> selectAllStaff(Integer pageNum, Integer pageSize) {
//        List<Staff> staffList = staffMapper.selectAllStaff();
//        retur;
//    }

    @Override
    public Page<Staff> selectAllStaff(Integer pageNum, Integer pageSize) {
        Page<Staff> page = new Page<>(pageNum,pageSize);
        Page<Staff> staffPage = staffMapper.selectPage(page,null);
        staffPage.getRecords().forEach(staff -> {staff.setOffice(officeMapper.selectById(staff.getOfficeId()));});
        return staffPage;
    }

    @Override
    public Staff selectStaffById(Staff staff) {
       Staff staff1 = staffMapper.selectStaffById(staff);
        return staff1;
    }

    @Override
    public int insertStaff(Staff staff) {
        return staffMapper.insert(staff);
    }

    @Override
    public int updateStaff(Staff staff) {
        return staffMapper.updateById(staff);
    }

    @Override
    public int changeStaffEnable(Staff staff) {
        return staffMapper.updateByPrimaryKey(staff);
    }

    @Override
    public Long getStaffCount() {
        return staffMapper.selectCount(null);
    }

}
